<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.fick.hibernate.model.Admin"%>
<%@ page import="com.fick.hibernate.dao.AdminDAO" %>
<%@ page import="com.fick.hibernate.model.Channel" %>
<%@ page import="com.fick.hibernate.dao.ChannelDAO" %>
<%@ page import="java.util.List" %>
<%@page import="com.fick.hibernate.dao.AdminQxDAO"%>
<%@page import="com.fick.hibernate.model.AdminQx"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>权限管理</title>
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.STYLE1 {font-size: 12px;}
.STYLE4 {
	font-size: 12px;
	color: #1F4A65;
	font-weight: bold;
}

a:link {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;

}
a:visited {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;
}
a:hover {
	font-size: 12px;
	color: #FF0000;
	text-decoration: underline;
}
a:active {
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}
.STYLE7 {font-size: 12px;}

</style>
	<link href="css/css.css" rel="stylesheet" type="text/css" />
	<link type="text/css" rel="stylesheet" href="js/xtree.css" />
	<script type="text/javascript" src="js/meihuaxue.js"></script>
<script type="text/javascript" >	
	function setValue(channelid){
var channel=document.getElementById(channelid);
if(channel.checked==false){channel.checked=true;}
   else{channel.checked=false;}
}
</script>
</head>
<%
	AdminDAO adminDao = new AdminDAO();
	List li = null;
	//得到记录数
	li = null;
	li = adminDao.findByHql("from Admin where role.id != 3 ");
	String nowuserid = request.getParameter("userid");
	if(nowuserid==null&&li.size()>0)
	{Admin admin=(Admin)li.get(0);
	nowuserid=String.valueOf(admin.getAdminId());
	}
%>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="30"><img src="images/tab_03.gif" width="15" height="30" /></td>
        <td width="1101" background="images/tab_05.gif"><img src="images/311.gif" width="16" height="16" />
			<span class="STYLE4">用户栏目权限管理页面</span></td>
        <td width="281" background="images/tab_05.gif">
        &nbsp;
        </td>
        <td width="14"><img src="images/tab_07.gif" width="14" height="30" /></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="9" background="images/tab_12.gif">&nbsp;</td>
        <td bgcolor="#f3ffe3">
        <form name="myform" action="<%=request.getContextPath() %>/admin/login.do?method=addAdminQx&userid=<%=nowuserid %>" method="post">
        <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
        <tr>
          <td width="60%" height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding:10px" class="STYLE1">
		  选择要分配权限的用户:
		    <select name="qx" onchange="sa(this)">
						<% 
							for(int i=0;i<li.size();i++)
							{
								Admin ad = (Admin)li.get(i);
								
								%>
								
<option value="<%=ad.getAdminId()%>" <%if(nowuserid!=null&&nowuserid.equals(ad.getAdminId()+""))out.print("selected"); %>><%=ad.getAdminName() %></option>
								
								<%
							}
						%>
			 </select>
			
		  </td>
        </tr>
        <%

		 if(nowuserid!=null){
        %>
		 <tr>
          <td width="60%" height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding:10px"class="STYLE1">
     <b>当前用户所拥有权限:</b><br><br>
					 <%AdminQxDAO qxdao=new AdminQxDAO();
					 List qxlist=qxdao.findByProperty("admin.adminId",Integer.parseInt(nowuserid));
					 for(int i=0;i<qxlist.size();i++)
					 { AdminQx qx=(AdminQx)qxlist.get(i);
					 Channel channel=qx.getChannel();
						 out.print(channel.getName()+"  ");
					 }
					 %>	
   		  </td>
          
		 </tr>
		  <tr>
		   
          <td width="60%" height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding:10px">
		   选中相应被赋予的权限:
				<div>
				<script>
				var curruserid="";
				</script>
				<%-- 动态树 --%>
				<script language="JavaScript">
                     var tree = new MzTreeView("tree");
                     tree.setIconPath("<%=request.getContextPath()%>/admin/TreeView/"); //可用相对路
                     tree.nodes["0_1"] = "text:栏目管理";
					 <%
						ChannelDAO channeldao=new ChannelDAO();
					 List channellist=channeldao.findAll();
					 for(int i=0;i<channellist.size();i++)
					 {Channel channel=(Channel)channellist.get(i);
					 %> 
					  
					   tree.nodes["<%=channel.getFatherId()%>_<%=channel.getChannelId()%>"] = "text:<input type=checkbox id=<%=channel.getChannelId() %> name=qxs value=<%=channel.getChannelId() %> <%for(int a=0;a<qxlist.size();a++) {  AdminQx qx=(AdminQx)qxlist.get(a);if(channel.getChannelId()==qx.getChannel().getChannelId()) {out.print("checked");}}%> /><%=channel.getName().replaceAll("'","‘").replaceAll("\"","”")%>;method:setValue('<%=channel.getChannelId()%>')";  
					 <%
					   }
					 %>
					 
				   tree.setTarget("MzMain");
				   document.write(tree.toString());    //亦可用 obj.innerHTML = tree.toString();
				   tree.expandAll();
				 </script>
		
				</div>
       

		   </td>
          
		 </tr>
		  <tr>
          <td width="60%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" >
            <input type="submit" value="提交">	 
       </td>
		 </tr>
		 <%} %>
      </table>
      </form>
        </td>
        <td width="9" background="images/tab_16.gif">&nbsp;</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td height="29">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="29"><img src="images/tab_20.gif" width="15" height="29" /></td>
        <td background="images/tab_21.gif">
        &nbsp;</td>
        <td width="14"><img src="images/tab_22.gif" width="14" height="29" /></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<script type="text/javascript">
 function sa(selected)
 {
 	var userid = selected.value;
 	var openurl = "<%=request.getContextPath() %>/admin/managerUserQx.jsp?userid="+userid; 
 	window.location.href=openurl;
 }
 </script>
